﻿using FyCaches.Core.Services;
using FyCaches.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FyCaches.Core.CommandHandlers
{
    internal class IsExistCommand
    {
        /// <summary>
        /// 判断指定的键是否存在
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        internal static byte Handle(CommandInfo command)
        {
            byte res = 0;
            try
            {
                //key
                string key = Encoding.UTF8.GetString(command.Frame.Frame, 40, command.Frame.Frame.Length - 40);

                var cache = CacheFlowService.Caches[command.DbIndex];
                if (cache.ContainsKey(key))
                    res = 1;
            }
            catch (Exception)
            {
                throw;
            }
            return res;
        }
    }
}
